package com.zy.design.demo.behavioral;

/**
 * 模板方法模式
 * 特点：定义算法的骨架，将步骤延迟到子类中实现。
 */
abstract class AbstractRecipe {
    public final void cookDish() {
        prepareIngredients();
        cook();
        serve();
    }

    protected abstract void prepareIngredients();
    protected abstract void cook();

    private void serve() { System.out.println("上菜！"); }
}

class FriedRice extends AbstractRecipe {
    @Override
    protected void prepareIngredients() { System.out.println("准备米饭和蔬菜"); }
    @Override
    protected void cook() { System.out.println("炒米饭"); }
}

class Main {
    public static void main(String[] args) {
        AbstractRecipe recipe = new FriedRice();
        recipe.cookDish();
    }
}
